﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
namespace Bouyei.GeoCore.GeoParsers.Parser
{
    using Geometries;
    using Bouyei.GeoCore.GeoParsers.Wkb;

    public class WkbParser : IDisposable
    {
        public GeoType GeometryType { get; private set; }
        private GeometryReader reader;
        private GeometryWriter writer;

        public WkbParser()
        {
            writer = new GeometryWriter();
        }

        public Geometry FromReader(byte[] buffer, int offset = 0)
        {
            using (reader = new GeometryReader(buffer, offset))
            {
                GeometryType = reader.GeometryType;
                return reader.Reader();
            }
        }

        public byte[] ToWriter(Geometry geometry)
        {
            return writer.Writer(geometry);
        }

        public void Dispose()
        {
            if (writer != null)
                writer.Dispose();
            if (reader != null)
                reader.Dispose();
        }
    }
}
